home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / src / demos / OpenGL / stonehenge / Ring.c++ < prev    next >
C/C++ Source or Header  |  1996-11-11  |  4KB  |  145 lines

  1. /*
  2.  * (c) Copyright 1993, Silicon Graphics, Inc.
  3.  * ALL RIGHTS RESERVED
  4.  *
  5.  * Permission to use, copy, modify, and distribute this software for
  6.  * any purpose and without fee is hereby granted, provided that the above
  7.  * copyright notice appear in all copies and that both the copyright notice
  8.  * and this permission notice appear in supporting documentation, and that
  9.  * the name of Silicon Graphics, Inc. not be used in advertising
  10.  * or publicity pertaining to distribution of the software without specific,
  11.  * written prior permission.
  12.  *
  13.  * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
  14.  * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
  15.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
  16.  * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
  17.  * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
  18.  * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
  19.  * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
  20.  * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
  21.  * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
  22.  * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
  23.  * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
  24.  * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
  25.  *
  26.  * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND
  27.  * Use, duplication, or disclosure by the Government is subject to
  28.  * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
  29.  * (c)(1)(ii) of the Rights in Technical Data and Computer Software
  30.  * clause at DFARS 252.227-7013 and/or in similar or successor
  31.  * clauses in the FAR or the DOD or NASA FAR Supplement.
  32.  * Unpublished-- rights reserved under the copyright laws of the
  33.  * United States.  Contractor/manufacturer is Silicon Graphics,
  34.  * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
  35.  *
  36.  * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
  37.  */
  38. #include <GL/glu.h>
  39. #include <GL/glx.h>
  40.  
  41. #include <math.h>
  42. #include <stdio.h>
  43.  
  44. #include "Ring.h"
  45.  
  46. inline float radians(float a) {return a * M_PI / 180.0;};
  47.  
  48. Ring::Ring() 
  49. {
  50.   Point sar_dim, lin_dim;
  51.  
  52.   radius = 10;
  53.  
  54.   nstones = 30;
  55.  
  56.   sar_dim.set(.2, .5, 1);
  57.   sarcen.set_dimensions(sar_dim);
  58.   sarcen.translate(radius, 0, sar_dim.pt[2]);
  59.  
  60.   angle = 360.0 / (float)nstones;
  61.  
  62.   lin_dim.set(.2, .99 * tan(2.0 * M_PI / (float)nstones) * 
  63.           (radius - sar_dim.pt[0]) / 2.0, .2);
  64.   lintel.set_dimensions(lin_dim);
  65.   lintel.translate(radius, 0, 2.*sar_dim.pt[2] + lin_dim.pt[2]);
  66. }
  67.  
  68.  
  69.  Ring::~Ring()
  70. {
  71. }
  72.  
  73. void Ring::erode(float p)
  74. {
  75.   sarcen.erode(p);
  76.   lintel.erode(p);
  77. }
  78.  
  79. void Ring::draw()
  80. {
  81.   draw_sarcens();
  82.   draw_lintels();
  83. }
  84.  
  85. void Ring::draw_sarcens()
  86. {
  87.   int i;
  88.   for (i = 0; i < nstones; i++) {
  89.     glPushMatrix();
  90.     glRotatef(i * angle, 0, 0, 1);
  91.     sarcen.draw();
  92.     glPopMatrix();
  93.   }
  94. }
  95.  
  96. void Ring::draw_lintels()
  97. {
  98.   int i;
  99.   glPushMatrix();
  100.   glRotatef(angle / 2.0, 0, 0, 1);
  101.   for (i = 0; i < nstones; i++) {
  102.     glPushMatrix();
  103.     glRotatef(i * angle, 0, 0, 1);
  104.     lintel.draw();
  105.     glPopMatrix();
  106.   }
  107.   glPopMatrix();
  108. }
  109.  
  110. void Ring::draw_shadow(Point dlight, GLfloat blur,
  111.                Color color, Color diffuse)
  112. {
  113.   draw_sarcens_shadows(dlight, blur, color, diffuse);
  114.   draw_lintels_shadows(dlight, blur, color, diffuse);
  115. }
  116.  
  117. void Ring::draw_sarcens_shadows(Point dlight, GLfloat blur,
  118.                 Color color, Color diffuse)
  119. {
  120.   int i;
  121.   Stone proto;
  122.  
  123.   proto = sarcen;
  124.   for (i = 0; i < nstones; i++) {
  125.     proto.rotate_self_aboutz(angle);
  126.     proto.draw_shadow(dlight, blur, color, diffuse);
  127.   }
  128. }
  129.  
  130. void Ring::draw_lintels_shadows(Point dlight, GLfloat blur,
  131.                 Color color, Color diffuse)
  132. {  
  133.   int i;
  134.   Stone proto;
  135.  
  136.   proto = lintel;
  137.  
  138.   proto.rotate_self_aboutz(angle / 2.0);
  139.  
  140.   for (i = 0; i < nstones; i++) {
  141.     proto.rotate_self_aboutz(angle);
  142.     proto.draw_shadow(dlight, blur, color, diffuse);
  143.   }
  144. }
  145.